package com.exam.controller;

import com.exam.entity.MultiQuestion;
import com.exam.service.MultiQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/multi-questions")
public class MultiQuestionController {

    @Autowired
    private MultiQuestionService multiQuestionService;

    @PostMapping
    public MultiQuestion addMultiQuestion(@RequestBody MultiQuestion multiQuestion) {
        return multiQuestionService.addMultiQuestion(multiQuestion);
    }

    @PutMapping("/{id}")
    public MultiQuestion updateMultiQuestion(@PathVariable Long id, @RequestBody MultiQuestion multiQuestion) {
        return multiQuestionService.updateMultiQuestion(id, multiQuestion);
    }

    @DeleteMapping("/{id}")
    public void deleteMultiQuestion(@PathVariable Long id) {
        multiQuestionService.deleteMultiQuestion(id);
    }

    @GetMapping("/{id}")
    public MultiQuestion getMultiQuestionById(@PathVariable Long id) {
        return multiQuestionService.getMultiQuestionById(id);
    }

    @GetMapping
    public List<MultiQuestion> getAllMultiQuestions() {
        return multiQuestionService.getAllMultiQuestions();
    }
@PostMapping("/import")
public void importMultiQuestions(@RequestBody List<MultiQuestion> multiQuestions) {
    multiQuestionService.importMultiQuestions(multiQuestions);
}

@PostMapping("/check-duplicate")
public boolean checkDuplicate(@RequestBody MultiQuestion multiQuestion) {
    return multiQuestionService.checkDuplicate(multiQuestion);
}
@GetMapping("/paged")
public Page<MultiQuestion> getAllMultiQuestionsPaged(
        @RequestParam(defaultValue = "0") int page, // 当前页
        @RequestParam(defaultValue = "10") int size // 每页大小
) {
    Pageable pageable = PageRequest.of(page, size);
    return multiQuestionService.getAllMultiQuestions(pageable);
}
}